//
//  SwiftUIView.swift
//  
//
//  Created by git on 2021/12/3.
//

import SwiftUI

@available(iOS 13.0, *)
struct SwiftUIView: View {
    var body: some View {
        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
    }
}

//@available(iOS 13.0, *)
//struct SwiftUIView2<Page: View>: UIViewRepresentable {
//    typealias UIViewType = <#type#>
//
//    var body: some View {
//        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
//    }
//}

@available(iOS 13.0, *)
struct PageViewController<Page: View>: UIViewControllerRepresentable {
    var pages: [Page]

    func makeUIViewController(context: Context) -> UIPageViewController {
        let pageViewController = UIPageViewController(
            transitionStyle: .scroll,
            navigationOrientation: .horizontal)

        return pageViewController
    }

    func updateUIViewController(_ pageViewController: UIPageViewController, context: Context) {
        pageViewController.setViewControllers(
            [UIHostingController(rootView: pages[0])], direction: .forward, animated: true)
    }
}

class ZGTouchView: UIView {
    init(){
        super.init(frame: CGRect.zero)
        self.setup()
    }
    
    func setup(){
        let lbl = UILabel(frame: CGRect(x: 20,y: 120,width: 100,height: 30))
        addSubview(lbl)
        lbl.text = "cccc"
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}


@available(iOS 13.0, *)
struct PageView<Page: UIView>:UIViewRepresentable {
    func makeUIView(context: Context) -> Page {
        return Page()
    }
    
    typealias UIViewType = Page
    
    func updateUIView(_ uiView: UIViewType, context: Context) {
        uiView.backgroundColor = .purple
    }
}


//<Page: View>:

@available(iOS 13.0, *)
struct SwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
//        SwiftUIView()
        PageView<ZGTouchView>()
    }
}
